<a href="<?php echo $this->webroot; ?>">Inicio</a><br/>
<?php
	if($session->check('Auth.User.id')){
		echo "Hola ";
		echo $session->read('Auth.User.username');
		echo " ";
		$subcategories = ClassRegistry::init('Subcategory')->find('all');
?>
	<a href="<?php echo $this->webroot; ?>/users/logout">Desconectar</a>
	
	<div class="main">
		<h3>Formulario de subida</h3>
		
		 <form action="images" method="POST" enctype="multipart/form-data">
		 	<p>Subcategoria:</p>
			 <select name="my_combobox">
				<?php foreach ($subcategories as $subcategory){?>
					<option	value="<?php echo $subcategory['Subcategory']['code'];?>"><?php echo $subcategory['Subcategory']['name']; ?></option>
				<?php }?>
			</select>
			<p>Nombre:</p>
			<input type="text" name="name" size="35"/>
			<p>Archivo (no más de 2MB por archivo y recuerda el tamaño ideal para promociones: 375x400):</p>
		    <input name="archivo" type="file" size="35" />
		    <p><input name="enviar" type="submit" value="Subir foto" /></p>
		    <input name="action" type="hidden" value="upload" />     
	    </form>
	    
	</div>
	<div class="main">
		<h3>Administración de menú</h3>
		
<?php
	$categories = ClassRegistry::init('Category')->find('all');
	foreach($categories as $category) {
		echo "<b>";
		echo $category['Category']['name'];
		echo "</b>";
		echo "<br />";
		$subcategories = $category['Subcategory'];
		echo "<ul>";
		foreach($subcategories as $subcategory) {
			echo "<li>";
			echo $subcategory['name'];
			echo "</li>";
			$subId = $subcategory['id'];
			
			$products = ClassRegistry::init('Product')->find('all',Array('conditions' => Array('Product.subcategory_id' => $subId)));
			echo "<ul>";
			foreach($products as $product){?>
				<li>
				<a href="<?php echo $this->webroot."img/upload/".$product['Image']['url_full']; ?>"><?php print_r($product['Product']['name']);?></a>
				<a onclick="return confirm('¿Seguro que quiere borrarlo?')" href="<?php echo $this->webroot; ?>users/borrar/<?php echo $product['Product']['id']?>">[Borrar]</a> <br />
				</li><?php
			}
			echo "</ul>";
		}
		echo "</ul>";
	}
	
	echo "<b>Promociones</b>";
	echo "<ul>";
	$promocionesID = ClassRegistry::init('Subcategory')->find('first',Array('conditions' => Array('Subcategory.name' => "Promociones")));
	//echo $promocionesID;// = $promocionesID['id'];
	$products = ClassRegistry::init('Product')->find('all',Array('conditions' => Array('Product.subcategory_id' => $promocionesID['Subcategory']['id'])));
	foreach ($products as $product){?>
			<a href="<?php echo $this->webroot."img/upload/".$product['Image']['url_full']; ?>"><?php print_r($product['Product']['name']);?></a>
			<a onclick="confirm('¿Seguro que quiere borrarlo?')" href="<?php echo $this->webroot; ?>users/borrar/<?php echo $product['Product']['id']?>">[Borrar]</a> <br />
		<?php }
	echo "</ul>";
	
	
	
?>
	</div>
<?php
}else {
	echo "No estas autorizado para ver lesta area.";	
}
?>
